<?php
//
// Wiki Page Class
// The SDMworld! Network
//


class clsWikiPage extends cDycmsObject
{
	protected $mClsId = 'WikiPage';

	private $msTitle;
	private $mBody;
	
	const allowedTags =
		'<p><br><em><b><i><u><strong>';

	function DoRender(cDycmsClientNode &$rnode)
	{
	 	// Uses cUiWikiLink
	 	uiLoadLibrary('page');
	 	
		$rnode->AddChild($hd = new cHtmlWrapperTag('div', array('class'=>'ContentTitle')));
		$rnode->AddChild($cnode = new cHtmlWrapperTag('div', array('class'=>'ContentBody')));
		$hd->AddChild($actions = new cHtmlWrapperTag('div', array('class'=>'wikiActions')));
		$hd->AddChild($this->msTitle);
		

		//
		// Add actions
		//
		
		$actions->AddChild(new cHtmlHyperlink(dyEditorUrl($this->mClsId, $this->mId),
			uiGetIcon('page_edit'), array('title'=>'Edit')));
		$actions->AddChild(new cHtmlHyperlink(dyEditorUrl($this->mClsId),
			uiGetIcon('page_add'), array('title'=>'New Page')));
		
		//
		// Begin parsing the Wiki markup
		//
		
		$cnode->AddChild(new cUiWikiRenderer(cUiWikiRenderer::$zDefaultToks,
				$this->mBody, $this->allowedTags));
	}

	function DrawEditor(cUiEditor &$editor)
	{
		//
		// Draw the editor form
		//

		$editor->AddChild(new cUiTextBox(array(
			'name'=>'$$WikiPage-title',
			'value'=>$this->msTitle
		),'Page Name'));
		$editor->AddChild(new cUiEditorTextArea('body', $this->mBody, null));
		
		//
		// Add buttons
		//
		
		$editor->AddChild(new cUiButtonSet(array(
			'name' => '$$os-editorAction',
			'method' => 'POST',
			'action' => ''), array(
			'save' => uiGetIcon('disk').'Save',
			'saveNew' => uiGetIcon('page_save').'Save As New',
			'view' => uiGetIcon('magnifier').'View'
		)));
	}
	
	function DoEdit($vzAttrib){
		parent::DoEdit($vzAttrib);
		if(isset($vzAttrib['$$WikiPage-title']))
			$this->msTitle = $vzAttrib['$$WikiPage-title'];
	}
	
	function Write(){
		parent::Write();
	 	
	 	// Publish it
	 	return $this->mClass->SetIndexValue($this->mId, 'title', $this->msTitle);
	}

	function GetSummary()
	{
		return $this->msTitle;
	}

	function LoadObject()
	{
		$this->msTitle = &$this->mClass->GetIndexValue($this->mId, 'title');
		$this->mBody = &$this->mAttributes['body'];
	}

    function Create(){$this->msTitle = 'New Wiki Page';}
}

?>
